package com.qf.web.servlet;

import com.qf.domain.Address;
import com.qf.domain.Cart;
import com.qf.domain.Order;
import com.qf.domain.User;
import com.qf.sevice.AddressService;
import com.qf.sevice.CartService;
import com.qf.sevice.Impl.AddressServiceImpl;
import com.qf.sevice.Impl.CartServiceImpl;
import com.qf.sevice.Impl.OrderServiceImpl;
import com.qf.sevice.OrderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * projectName:Shopping
 * author:RongChao
 * time:2022/4/20 21:38
 * description:
 */
@WebServlet("/orderservlet")
public class OrderServlet extends BaseServlet {
        CartService cartService = new CartServiceImpl();
        AddressService addressService = new AddressServiceImpl();
        OrderService orderService = new OrderServiceImpl();

        public String addOrder(HttpServletRequest request, HttpServletResponse response) throws Exception {
            User user = (User) request.getSession().getAttribute("user");
            String aid = request.getParameter("aid");
            Order order=orderService.addOrder(user.getId(),aid);
            request.setAttribute("order", order);
            return "forward:/orderSuccess.jsp";
        }






        public String getOrderView(HttpServletRequest request, HttpServletResponse response) throws Exception {
        User user = (User) request.getSession().getAttribute("user");
        //获取购物车信息
        List<Cart> carts = cartService.findCartByUid(user.getId());
        request.setAttribute("carts",carts);
        //查询该用户的地址列表信息
        List<Address> addList = addressService.findAddListByUid(user.getId());
        request.setAttribute("addList", addList);
        return "forward:/order.jsp";
    }
}
